package com.example.demo.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author linjingze
 * @date 2023/12/18 9:33 AM
 */
public class CalculateUtils {

    public static void main(String[] args) {
        System.out.println(getPrice(false, new BigDecimal("0"), new BigDecimal("7.2"), new BigDecimal("3.57"), new BigDecimal("4.22"), null));
    }

    public static BigDecimal getRT(boolean isTaxFarming, BigDecimal weight, BigDecimal volume) {
        if (isTaxFarming) {
            BigDecimal volumeWeight = BigDecimalUtils.mul(volume, new BigDecimal("167"));
            return BigDecimalUtils.max(BigDecimalUtils.max(volumeWeight, weight), new BigDecimal("100"));
        }
        BigDecimal volumeWeight = BigDecimalUtils.div(weight, new BigDecimal("363"));
        return BigDecimalUtils.max(BigDecimalUtils.max(volumeWeight, volume), new BigDecimal("1"));
    }

    public static BigDecimal getPrice(boolean isTaxFarming,
                                      BigDecimal deliveryPrice,
                                      BigDecimal exchangeRate,
                                      BigDecimal rt,
                                      BigDecimal bsHeadPrice,
                                      BigDecimal unBsHeadPrice) {
        BigDecimal deliveryExchangeRatePrice = BigDecimalUtils.mulKeep4Scale(deliveryPrice, exchangeRate);
        if (isTaxFarming) {
            BigDecimal price = BigDecimalUtils.divKeep8Scale(deliveryExchangeRatePrice, rt);
            return BigDecimalUtils.add(price, bsHeadPrice).setScale(1, RoundingMode.HALF_UP);
        } else {
            BigDecimal price  = BigDecimalUtils.divKeep0Scale(deliveryExchangeRatePrice, rt);
            return BigDecimalUtils.roundToNearestTen(BigDecimalUtils.add(price, unBsHeadPrice));
        }
    }



    public static BigDecimal getUseBoard(BigDecimal volume) {
        return BigDecimalUtils.customRound(BigDecimalUtils.div(volume, new BigDecimal("1.8"))).setScale(0, RoundingMode.UP);
    }

    public static BigDecimal getTaxFarmingTaxAmount(BigDecimal rt, BigDecimal exchangeRate) {

        BigDecimal price = BigDecimalUtils.mul(rt, new BigDecimal("0.5"));
        return BigDecimalUtils.divKeep6Scale(price, exchangeRate);
    }

}

